﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Command;
using BonsaiScrum.Bus;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Core.Domain;

namespace BonsaiScrum.Core.CommandHandlers
{
    public class CreateTaskHandler : ICommandHandler<CreateTask>
    {
        private readonly IDomainRepository _domainRepository;

        public CreateTaskHandler(IDomainRepository domainRepository)
        {
            _domainRepository = domainRepository;
        }

        public void Handle(CreateTask message)
        {
            var user = _domainRepository.GetById<User>(message.CreatedBy);
            var project = _domainRepository.GetById<Project>(message.ProjectId);

            project.AddTask(message.Description, message.Priority, user, message.StoryId);
        }
    }
}
